<?php

/**
 * 产品类型表
 */
class news_type extends CActiveRecord
{
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'news_type';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		return array(
			array('cn_name,en_name', 'safe'),
		);
	}

	/**
	 * 返回类型数据
	 * @param string $lang
	 *
	 * @return mixed
	 */
	function getTypeData($lang=''){
		if($lang=='en'){
			$sql="SELECT *,`en_name` as `type_name` FROM `".$this->tableName()."` GROUP BY `en_name` ORDER BY `id` ASC";
		}else{
			$sql="SELECT *,`cn_name` as `type_name` FROM `".$this->tableName()."` GROUP BY `cn_name` ORDER BY `id` ASC ";
		}
		$data=news_type::getDbConnection()->createCommand($sql)->queryAll();
		return $data;
	}




}
